namespace Example.Client
{
    using System;
    using System.ServiceModel;

    /// <summary>
    /// The service contract is defined in generatedProxy.cs, generated from the service by the svcutil tool.
    /// </summary>
    public static class Program
    {
        public static void Main()
        {
            // Create a proxy with Username endpoint configuration
            var proxy = new CalculatorProxy("Username");

            try
            {
                var credentials = proxy.ClientCredentials;
                if (null == credentials)
                {
                    throw new InvalidOperationException("Credentials are unexpectedly null");
                }

                credentials.UserName.UserName = "test1";
                credentials.UserName.Password = "1tset";

                // Call the Add service operation.
                var value1 = 100.00D;
                var value2 = 15.99D;
                var result = proxy.Add(value1, value2);
                Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result);

                // Call the Subtract service operation.
                value1 = 145.00D;
                value2 = 76.54D;
                result = proxy.Subtract(value1, value2);
                Console.WriteLine("Subtract({0},{1}) = {2}", value1, value2, result);

                // Call the Multiply service operation.
                value1 = 9.00D;
                value2 = 81.25D;
                result = proxy.Multiply(value1, value2);
                Console.WriteLine("Multiply({0},{1}) = {2}", value1, value2, result);

                // Call the Divide service operation.
                value1 = 22.00D;
                value2 = 7.00D;
                result = proxy.Divide(value1, value2);
                Console.WriteLine("Divide({0},{1}) = {2}", value1, value2, result);
                proxy.Close();
            }
            catch (TimeoutException e)
            {
                Console.WriteLine("Call timed out : {0}", e.Message);
                proxy.Abort();
            }
            catch (CommunicationException e)
            {
                Console.WriteLine("Call failed : {0}", e.Message);
                proxy.Abort();
            }
            catch (Exception e)
            {
                Console.WriteLine("Call failed : {0}", e.Message);
                proxy.Abort();
            }

            Console.WriteLine();
            Console.WriteLine("Press <ENTER> to terminate client.");
            Console.ReadLine();
        }
    }
}